import allure,pytest
import loguru
from loguru import logger
from faker import Faker
faker1 = Faker(locale='zh_cn')
from api_util.api_util import *
from business.login.login_test_branch_office import TestCaseCmord as Login
from common.read_json import Read_Json
json_data = Read_Json("VirtualComments.json").get_json_data()
json_data['comment'] = faker1.name()
admin = perform_requests()
@allure.story("虚拟评论")
class TestVirtualComments():
    @pytest.fixture(scope='function', autouse=True)
    @allure.story("数据清除")
    def setup_function(self, request):
        print("测试开始了哦~")
        def teardown_function():
            print("测试结束~")
        request.addfinalizer(teardown_function)
        # 此内嵌函数做teardown工作
    @allure.story("添加虚拟评论")
    def test_AddVirtualComments(self):
        admin.reset_request_step(Login)  # todo: 登录文件引用，默认不传是GetToken
        # todo： 创建请求方法  create_search_parts 可自定义命名。调用create_run_request方法，传入API名称、API地址、request body
        create_VirtualComments = \
            admin.create_run_request('post',
                "添加虚拟评论", "adminapi/product/reply/save_fictitious_reply.html",json_data) \
                .validate() \
                .assert_equal("status_code", 200)\
                .assert_equal('headers."Content-Type"', "application/json; charset=utf-8")\
                .assert_equal("body.status", 200)\
                .assert_equal("body.msg", "添加成功!")
        # todo:   contruct_request_step  放入执行步骤，如果有多个，需要逗号隔开
        create_VirtualComments_step = admin.contruct_request_step(
            create_VirtualComments)
        # todo：  perform_requests_and_get_last_response  放入需要执行用例，同样，如果有多个，需要逗号隔开
        res = admin.perform_requests_and_get_last_response(
            [create_VirtualComments_step])




